package restaurant;

/**
 * The Command object to order an item.
 * 
 * @author Odessa
 */

public class cmdOrderItem implements Command
{

	/** The information aggregator. */
	private InformationAggregator info;

	/** The table placing the order. */
	private int tableNo;

	/** The item being ordered. */
	private int itemNo;

	/** The price of the item being ordered. */
	private double price;



	/**
	 * Instantiates a new order item command.
	 * 
	 * @param info the system's information.
	 * @param tableNo the table number that places the order.
	 * @param itemNo the item being ordered.
	 * @param price the price of the item being ordered.
	 */
	public cmdOrderItem(InformationAggregator info, int tableNo, int itemNo,
			double price) {
		this.info = info;
		this.tableNo = tableNo;
		this.itemNo = itemNo;
		this.price = price;
	}



	/**
	 * Creates an order for an item and adds the order to the kitchen queue.
	 * Then sets the table as having placed an order.
	 * 
	 * @return the newly created order.
	 * @see restaurant.Command#execute()
	 */
	@Override
	public Object execute()
	{
		CustomerOrders orders = info.getOrders();
		Order newOrder = orders.newOrder(itemNo, price);
		info.addToKitchenQueue(newOrder);

		CustomerTabs tabs = info.getTabs();
		Tab tab = tabs.getTableTab(tableNo);
		int tabNo = tab.getTabNo();
		tabs.addToTab(tabNo, itemNo, price);

		Tables tables = info.getTables();
		tables.orderPlaced(tableNo);

		return newOrder;
	}

}
